//（公共的common.js，可以放在根目录的js文件夹下，url：接口，method：请求方式，data：请求的json参数）
import apiConf from '../apiConfs/api' ;
module.exports.requestServerData = function (url, method, data) {
  wx.showNavigationBarLoading();
  wx.showLoading({
    title:'加载中...'
  });
  return new Promise(function (resolve, reject) {
    let token = wx.getStorageSync('token')
    wx.request({
      url: apiConf.prefix.local +'/'+url,
      data: data,
      header: {
        'content-type': 'application/json',
        'token':token
      },
      method: method,
      success: function (res) {
        wx.hideLoading()
        wx.hideNavigationBarLoading();
        resolve(res)
      },
      fail: function (res) {
        wx.hideLoading()
        wx.hideNavigationBarLoading();
        wx.showModal({
          title: '提示',
          content:"请求失败",
        })
        reject(res)
      }
    })
  })
}
